import sys

from PySide6.QtWidgets import QApplication, QMainWindow, QLineEdit

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("My App")

        widget = QLineEdit()
        widget.setMaxLength(10)
        widget.setPlaceholderText("Enter your text")
        widget.setInputMask("000.000.000.000;_")

        widget.returnPressed.connect(self.return_pressed) # 回车
        widget.selectionChanged.connect(self.selection_changed) # 选中
        widget.textChanged.connect(self.text_changed)  #文本改变
        widget.textEdited.connect(self.text_edited) #文本编辑

        self.setCentralWidget(widget)

    def return_pressed(self):
        print("Return pressed")
        self.centralWidget().setText("BOOM!")

    def selection_changed(self):
        print("Selection changed")
        print(self.centralWidget().selectedText())

    def text_changed(self, s):
        print("Text changed...")
        print(s)

    def text_edited(self, s):
        print("Text edited...")
        print(s)


app = QApplication(sys.argv)
window = MainWindow()
window.show()

app.exec()

